﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuanLyChungCu_V.BussinessTỉer
{
    class ViPhamManagerService
    {
        
        SQLConnection sql_conn;
        public ViPhamManagerService()
        {
            try
            {
                sql_conn = new SQLConnection(null); // Lay ConnectionString trong DataConnection.xml, neu file khong ton tai thi tao moi va ghi lai ConnectionString
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
        }
        


      
        
        public void AddViPham(string name, string htxl)

        {
            QLCCDataContext ctx = new QLCCDataContext();
            ctx.Connection.ConnectionString = sql_conn.ConnectionString;
            ctx.ViPhams.InsertOnSubmit(new ViPham
            {
                TenVP = name,
                HTXuLy = htxl,
               
            });
            ctx.SubmitChanges();
        }
        public IList<ViPhamDTO> FindViPham(string name)
        {
            QLCCDataContext ctx = new QLCCDataContext();
            ctx.Connection.ConnectionString = sql_conn.ConnectionString;

            var vipham = from p in ctx.ViPhams
                         where p.TenVP.Contains(name)
                         select new ViPhamDTO
                         {
                             id = p.idViPham,
                             name = p.TenVP,
                            htxl = p.HTXuLy,
                         };
            return vipham.ToList<ViPhamDTO>();
        }
    }
}
